package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TeamSysinfo;
import com.ruoyi.system.service.ITeamSysinfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统信息Controller
 * 
 * @author ruoyi
 * @date 2021-11-14
 */
@Controller
@RequestMapping("/system/sysinfo")
public class TeamSysinfoController extends BaseController
{
    private String prefix = "system/sysinfo";

    @Autowired
    private ITeamSysinfoService teamSysinfoService;

    @RequiresPermissions("system:sysinfo:view")
    @GetMapping()
    public String sysinfo()
    {
        return prefix + "/sysinfo";
    }

    /**
     * 查询系统信息列表
     */
    @RequiresPermissions("system:sysinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeamSysinfo teamSysinfo)
    {
        startPage();
        List<TeamSysinfo> list = teamSysinfoService.selectTeamSysinfoList(teamSysinfo);
        return getDataTable(list);
    }

    /**
     * 导出系统信息列表
     */
    @RequiresPermissions("system:sysinfo:export")
    @Log(title = "系统信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeamSysinfo teamSysinfo)
    {
        List<TeamSysinfo> list = teamSysinfoService.selectTeamSysinfoList(teamSysinfo);
        ExcelUtil<TeamSysinfo> util = new ExcelUtil<TeamSysinfo>(TeamSysinfo.class);
        return util.exportExcel(list, "系统信息数据");
    }

    /**
     * 新增系统信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统信息
     */
    @RequiresPermissions("system:sysinfo:add")
    @Log(title = "系统信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeamSysinfo teamSysinfo)
    {
        teamSysinfo.setUpdatedBy(getLoginName());
        teamSysinfo.setCreatedBy(getLoginName());
        return toAjax(teamSysinfoService.insertTeamSysinfo(teamSysinfo));
    }

    /**
     * 修改系统信息
     */
    @GetMapping("/edit/{sysId}")
    public String edit(@PathVariable("sysId") String sysId, ModelMap mmap)
    {
        TeamSysinfo teamSysinfo = teamSysinfoService.selectTeamSysinfoBySysId(sysId);
        mmap.put("teamSysinfo", teamSysinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统信息
     */
    @RequiresPermissions("system:sysinfo:edit")
    @Log(title = "系统信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeamSysinfo teamSysinfo)
    {
        teamSysinfo.setUpdateBy(getLoginName());
        return toAjax(teamSysinfoService.updateTeamSysinfo(teamSysinfo));
    }

    /**
     * 删除系统信息
     */
    @RequiresPermissions("system:sysinfo:remove")
    @Log(title = "系统信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(teamSysinfoService.deleteTeamSysinfoBySysIds(ids));
    }
}
